import { createRouter, createWebHashHistory, createWebHistory } from "vue-router";
// routes
const routes = [
    {
        redirect: "/home",
        path: "/"
    },
    // 首页
    {
        path: '/home',
        name: "home",
        component: () => import("@/views/home/index.vue")
    },
    // 管理页
    {
        path: '/manage',
        name: "manage",
        component: () => import("@/views/manage/index.vue"),
        children: [
            // 组委会菜单路由
            // 组委会信息
            {
                path: 'organizingmation',
                name: "manage-organizingmation",
                component: () => import('@/views/manage/organcommitmenu/organizingmation.vue'),
                meta: {
                    index: "manage-organizingmation",
                }

            },
            // 组委会管理
            {
                path: 'agentmanagement',
                name: "manage-agentmanagement",
                component: () => import('@/views/manage/organcommitmenu/agentmanagement.vue'),
                meta: {
                    index: "manage-agentmanagement",
                }
            },
            // 机构管理
            {
                path: 'organtionmanagement',
                name: "manage-organtionmanagement",
                component: () => import('@/views/manage/organcommitmenu/organtionmanagement.vue'),
                meta: {
                    index: "manage-organtionmanagement",
                }
            },
            // 报名管理 
            {
                path: 'registrationmanagement',
                name: "manage-registrationmanagement",
                component: () => import('@/views/manage/organcommitmenu/registrationmanagement.vue'),
                meta: {
                    index: "manage-registrationmanagement",
                }
            },
            // 准考证管理 TODO
            {
                path: 'admission_ticket',
                name: "admission_ticket",
                component: () => import('@/views/manage/organcommitmenu/admission_ticket.vue'),
                meta: {
                    index: "manage-registrationmanagement",
                }
            },
            // 考场管理 TODO
            {
                path: 'test_questions',
                name: "test_questions",
                component: () => import('@/views/manage/organcommitmenu/test_questions.vue'),
                meta: {
                    index: "manage-registrationmanagement",
                }
            },
            // 试题管理 TODO
            {
                path: 'examination_room',
                name: "examination_room",
                component: () => import('@/views/manage/organcommitmenu/examination_room.vue'),
                meta: {
                    index: "manage-registrationmanagement",
                }
            },
            // ID码管理
            {
                path: 'id-manage',
                name: "manage-id-manage",
                component: () => import('@/views/manage/organcommitmenu/id-manage.vue'),
                meta: {
                    index: "manage-registrationmanagement",
                }
            },
            // 人员管理
            {
                path: 'personnelmanagement',
                name: "manage-personnelmanagement",
                component: () => import('@/views/manage/organcommitmenu/personnelmanagement.vue'),
                meta: {
                    index: "manage-personnelmanagement",
                }
            },
            // 参赛人员
            {
                path: 'cansaientryreview',
                name: "manage-cansaientryreview",
                // component: () => import('@/views/manage/organcommitmenu/cansaientryreview.vue'),
                component: () => import('@/views/manage/agentmenu/organization.vue'),
                meta: {
                    index: "manage-cansaientryreview",
                }
            },
            // 统计与报表
            {
                path: 'tongjistatements',
                name: "manage-tongjistatements",
                // component: () => import('@/views/manage/organcommitmenu/tongjistatements.vue'),
                component: () => import('@/views/manage/agentmenu/statisticstements.vue'),
                meta: {
                    index: "manage-tongjistatements",
                }
            },
            // ID码获取
            {
                path: 'IDCodeAcquisition',
                name: "manage-IDCodeAcquisition",
                // component: () => import('@/views/manage/organcommitmenu/tongjistatements.vue'),
                component: () => import('@/views/manage/agentmenu/idcode.vue'),
                meta: {
                    index: "manage-IDCodeAcquisition",
                }
            },
            // 分组管理
            {
                path: 'fenzugroupmanagement',
                name: "manage-fenzugroupmanagement",
                component: () => import('@/views/manage/organcommitmenu/fenzugroupmanagement.vue'),
                meta: {
                    index: "manage-fenzugroupmanagement",
                }
            },
            // 赛项类型管理
            {
                path: 'event_type',
                name: "manage-event_type",
                component: () => import('@/views/manage/organcommitmenu/event_type.vue'),
                meta: {
                    index: "manage-event_type",
                }
            },

            // -----------------------------------------------------------------------------------------------------------------------------
            // 组委会菜单路由
            {
                path: 'committee',
                name: "manage-committee",
                component: () => import('@/views/manage/agentmenu/committee.vue'),
                meta: {
                    index: "manage-committee",
                }
            },
            {
                path: 'agents',
                name: "manage-agents",
                component: () => import('@/views/manage/agentmenu/agents.vue'),
                meta: {
                    index: "manage-agents",
                }
            },
            // 查询机构信息
            {
                path: 'agents/details/:eventId',
                name: "manage-agents-details",
                component: () => import('@/views/manage/agentmenu/registration/details.vue'),
                meta: {
                    index: "manage-agents",
                }
            },
            /**
             * 参赛人员管理
             */
            {
                path: 'organization',
                name: "manage-organization",
                component: () => import('@/views/manage/agentmenu/organization.vue'),
                meta: {
                    index: "manage-organization",
                }
            },
            // 统计与报表路由
            {
                path: 'statisticstements',
                name: "manage-statisticstements",

                component: () => import('@/views/manage/agentmenu/statisticstements.vue'),
                meta: {
                    index: "manage-statisticstements",
                }
            },

            // -----------------------------------------------------------------------------------------------------------------------------
            // 机构菜单路由
            {
                path: 'organizationinfo',
                name: "manage-organizationinfo",
                component: () => import('@/views/manage/menusubassembly/organizationinfo.vue'),
                meta: {
                    index: "manage-organizationinfo",
                }
            },
            // 人员管理路由
            {
                path: 'personnel',
                name: "manage-personnel",
                component: () => import('@/views/manage/menusubassembly/personnel.vue'),
                meta: {
                    index: "manage-personnel",
                }
            },
            // 报名管理路由
            {

                path: 'registration',
                name: "manage-registration",
                component: () => import('@/views/manage/menusubassembly/registration.vue'),
                meta: {
                    index: "manage-registration",
                }
            },
            // 报名管理
            {
                path: 'registration/details/:eventId',
                name: "manage-registration-details",
                component: () => import('@/views/manage/menusubassembly/registration/details.vue'),
                meta: {
                    index: "manage-registration",
                }
            },
            // ID码助手路由
            {

                path: 'idassistant',
                name: "manage-idassistant",
                component: () => import('@/views/manage/menusubassembly/idassistant.vue'),
                meta: {
                    index: "manage-organizationinfo",
                }
            },
            // 批阅老师----------------------------------------------------------------------
            // 老师信息
            {

                path: 'tecinfo',
                name: "tecinfo",
                component: () => import('@/views/manage/tec/tecinfo.vue'),
                meta: {
                    index: "tecinfo",
                }
            },
            // 待批阅
            {

                path: 'wait_list',
                name: "wait_list",
                component: () => import('@/views/manage/tec/wait_list.vue'),
                meta: {
                    index: "wait_list",
                }
            },
        ]
    },
    // auth
    {
        path: '/auth',
        redirect: "/auth/login",
        component: () => import("@/views/auth/index.vue"),
        children: [
            {
                path: 'login',
                component: () => import("@/views/auth/login.vue")
            },
            {
                path: 'teclogin',
                component: () => import("@/views/auth/teclogin.vue")
            },
            {
                path: 'reg',
                component: () => import("@/views/auth/reg.vue")
            },
            {
                path: 'forgetpassword',
                name: 'forgetpassword',
                component: () => import("@/views/auth/forgetpassword.vue")
            },
        ]
    },
    {
        path: '/:pathMatch(.*)*', component: () => import("@/views/404.vue")
    },

]

// router
const router = createRouter({
    history: import.meta.env.VITE_MODE == 'dev' ? createWebHashHistory() : createWebHistory(),
    routes
});
// 无需登录的页面
const LOGIN_ROUTERS = "manage"
router.beforeEach((to, from, next) => {
    if (to.fullPath.indexOf(LOGIN_ROUTERS) != -1) {
        let token = localStorage.getItem("token")
        if (!token) {
            return next("/auth/login");
        }
    }
    return next(true)
})
export default router;